home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / print / proff.zip / PUTWRD.C < prev    next >
C/C++ Source or Header  |  1988-02-12  |  1KB  |  49 lines

  1. #include <stdio.h>
  2. #include "proff.h"
  3. #include "debug.h"
  4.  
  5. /*
  6.  * putwrd - put a word in outbuf; includes margin justification
  7.  *
  8.  */
  9. putwrd(wrdbuf)
  10. char wrdbuf[];
  11. {
  12.     int last, llval, extra, w;
  13.  
  14. dprintf("putwrd  ");
  15.     w = width(wrdbuf);
  16.     last = strlen(wrdbuf) + outp;         /* new end of outbuf */
  17. #ifdef DEBUG
  18. printf("strlen(wrdbuf) = %d\n",strlen(wrdbuf));
  19. #endif
  20.     llval = rmval - tival;
  21.     if (outw + w > llval || last >= MAXOUT) {    /* too big */
  22.         last -= outp;
  23.         extra = llval - outw;
  24. #ifdef DEBUG
  25. printf("extra = %d\n",extra);
  26. #endif
  27.         for ( ; outp > 0; outp--)
  28.             if (outbuf[outp-1] == ' ')
  29.                 extra++;
  30.             else
  31.                 break;
  32.         if (rjust == YES) {
  33.             spread(outbuf, outp, extra, outwds);
  34.             if (extra > 0 && outwds > 1)
  35.                 outp += extra;
  36.         }
  37.         lbrk();        /* flush previous line */
  38.     }
  39. #ifdef DEBUG
  40. printf("putwrd: last=%d w=%d outp=%d llval=%d outw=%d extra=%d\n",
  41.         last,w,outp,llval,outw,extra);
  42. #endif
  43.     strcpy(&outbuf[outp],wrdbuf);
  44.     outp = last;
  45.     outw += w;
  46.     outwds++;
  47. }
  48.  
  49.